﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace Common.DataAnnotations
{
    /// <summary>
    /// 双精度浮点数取值范围
    /// </summary>
    public class RangeDoubleAttribute : RangeAttribute
    {
        /// <summary>
        /// 双精度浮点数取值范围
        /// </summary>
        public RangeDoubleAttribute()
             : base(0.01d, double.MaxValue)
        {

        }

        /// <summary>
        /// 双精度浮点数取值范围
        /// </summary>
        /// <param name="minimum"></param>
        /// <param name="maximum"></param>
        public RangeDoubleAttribute(double minimum, double maximum)
            : base(minimum, maximum)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            if (string.IsNullOrEmpty(this.ErrorMessage))
            {
                return string.Format("{0}无效，必须在{1}至{2}之间！", name, Minimum, Maximum);
            }
            else
            {
                return string.Format(this.ErrorMessage, name, Minimum, Maximum);
            }
        }
    }
}
